package com.ruiyian.bridge.opreations.controller;

import com.ruiyian.bridge.opreations.domain.Sms;
import com.ruiyian.bridge.opreations.service.SmsService;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.domain.entity.Equipment;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author chong
 * @email 673426164@qq.com
 * @create 2022/5/7
 * Desc: 短信
 */
@RestController
@RequestMapping("/bm/sms")
public class SmsController extends BaseController {
    @Autowired
    private SmsService smsService;

    /**
     * 分页查询
     * @param sms
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(Sms sms)
    {
        startPage();
        List<Sms> list = smsService.getList(sms);
        return getDataTable(list);
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(smsService.getOne(id));
    }

    /**
     * 处理
     */
    @PostMapping
    public AjaxResult add(@RequestBody Sms sms)
    {
        smsService.update(sms);
        return AjaxResult.success();
    }

    @PostMapping(value = "/export")
    public AjaxResult export(HttpServletResponse response , @RequestBody Sms sms) {
        List<Sms> list = smsService.getList(sms);
        ExcelUtil<Sms> util = new ExcelUtil<>(Sms.class);
        return util.exportExcel(list, "短信提醒");
    }
}
